<template>
	<camera @stop="stop" @ready="ready" flash="off" @error="error" class="cameras" device-position="front">
	</camera>
</template>

<script>
export default {
	name: "ExamPhoto",
	components: {
		x: 0,
		y: 0,
	},
	data() {
		return {

		};
	},
	props: [],
	methods: {
		onChange(e) {
			this.x = e.detail.x
			this.y = e.detail.y
		},
		takePhoto() {
			return new Promise((resolve, reject) => {
				const ctx = uni.createCameraContext();
				ctx.takePhoto({
					quality: 'high',
					success: (res) => {
						const fs = wx.getFileSystemManager();
						fs.readFile({
							filePath: res.tempImagePath,
							encoding: 'base64',
							success(res) {
								const photoBase64 = 'data:image/png;base64,' + res.data;
								resolve(photoBase64); // 返回 base64 数据
							},
							fail(error) {
								reject(error);
							}
						});
					},
					fail(error) {
						reject(error);
					}
				});
			});
		},
		error(e) {
			console.log(e);

		},
		stop(e) {
			console.log(e);
		},
		ready(e) {
			console.log(e);
		}
	},
}
</script>

<style lang="scss">
.cameras {
	width: 110px;
	height: 160px;
	border-radius: 10px;
	z-index: 10000;
}

.cameras-movable-area {
	width: 100vw;
	height: 100vh;
	position: relative;
	top: 0;
	left: 0;
}
</style>